﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace YFIN.Helper
{
    public class VerifyCode
    {
        public static KeyValuePair<string, Bitmap> GetVerifyCode()
        {
            var r = new Random();
            var x = r.Next(0, 20);
            var y = r.Next(0, 20);
            var o = r.Next(0, 1);
            var bitmap = new Bitmap(100, 40);
            var g = Graphics.FromImage(bitmap);
            string s = x + " " + (o == 0 ? "+" : "-") + " " + y;
            g.DrawString(s, new Font("Arial", 16), SystemBrushes.ControlText, 12, 12);
            var c = r.Next(3, 6);
            for (int i = 0; i < c; i++)
            {
                g.DrawLine(new Pen(Color.FromArgb(r.Next()), 1),
                    r.Next(0, 20), r.Next(0, 20), r.Next(0, 20), r.Next(0, 20));
            }
            g.Dispose();
            string res = (o == 0 ? x + y : x - y).ToString();
            return new KeyValuePair<string, Bitmap>(res, bitmap);
        }
    }
}
